class Solution {
public:
    vector<int> singleNumbers(vector<int>& nums) {
        int sum = 0;
        for (const auto& num : nums)
            sum ^= num;
        int m = 1;
        while ((sum & m) == 0)
            m <<= 1;
        int x = 0;
        int y = 0;
        for (const auto& num : nums)
        {
            if (num & m)
                x ^= num;
            else
                y ^= num;
        }
        return vector<int>{ x, y };
    }
};